package com.aqie.haikang.dorm.runner;

import com.aqie.haikang.dorm.crontab.DynamicScheduleTask;
import com.aqie.haikang.dorm.entity.Cron;
import com.aqie.haikang.dorm.service.ICronService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author aqie
 * @Date 2021/12/15 13:43
 * @desc
 */
@Slf4j
@Component
public class ApplicationRunnerImpl implements ApplicationRunner {

    @Autowired
    private ICronService cronService;

    @Autowired
    private DynamicScheduleTask scheduleTask;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        List<Cron> list = cronService.list();
        scheduleTask.refresh(list);
    }
}
